package com.longdaji.decoration.ui.main.community;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.longdaji.decoration.R;
import com.longdaji.decoration.adapter.MyFragmentPagerAdapter;
import com.longdaji.decoration.base.BaseFragment;
import com.longdaji.decoration.ui.activitiesOfCommunity.hotVideo.HotVideoActivity;
import com.longdaji.decoration.ui.activitiesOfCommunity.news.NewsActivity;
import com.longdaji.decoration.ui.activitiesOfCommunity.publishDynamic.PublishDynamicActivity;
import com.longdaji.decoration.ui.activitiesOfCommunity.publishVideo.PublishVideoActivity;
import com.longdaji.decoration.ui.main.MainActivity;
import com.longdaji.decoration.ui.main.community.innerFragment.DynamicFragment;
import com.longdaji.decoration.ui.main.community.innerFragment.FollowFragment;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by longtao on 2018/1/14.
 */

public class CommunityFragment extends BaseFragment implements CommunityContract.View {

    @Inject
    CommunityContract.Presenter mPresenter;
    @Inject
    DynamicFragment dynamicFragment;
    @Inject
    FollowFragment followFragment;

    @BindView(R.id.iv_tool_one)
    ImageView ivToolOne;
    @BindView(R.id.iv_tool_two)
    ImageView ivToolTwo;
    @BindView(R.id.iv_tool_three)
    ImageView ivToolThree;
    @BindView(R.id.ll_publish_dynamic)
    LinearLayout llPublishDynamic;
    @BindView(R.id.ll_hot_video)
    LinearLayout llHotVideo;
    @BindView(R.id.ll_publish_video)
    LinearLayout llPublishVideo;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;

    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private List<Fragment> fragments = new ArrayList<>();

    @Inject
    public CommunityFragment() {
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_community;
    }

    @Override
    protected void initView() {
        if (mPresenter != null) {
            mPresenter.setView(this);
        }
        fragments.add(dynamicFragment);
        fragments.add(followFragment);
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getActivity().getSupportFragmentManager(), fragments, new String[]{"动态", "关注"});
        viewPager.setAdapter(myFragmentPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabGravity(Gravity.FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }

    @OnClick({R.id.iv_tool_one, R.id.iv_tool_two, R.id.iv_tool_three, R.id.ll_publish_dynamic, R.id.ll_hot_video, R.id.ll_publish_video})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_tool_one:
                break;
            case R.id.iv_tool_two:
                break;
            case R.id.iv_tool_three:
                startActivity(new Intent(getActivity(), NewsActivity.class));
                break;
            case R.id.ll_publish_dynamic:
                startActivity(new Intent(getActivity(), PublishDynamicActivity.class));
                break;
            case R.id.ll_hot_video:
                startActivity(new Intent(getActivity(), HotVideoActivity.class));
                break;
            case R.id.ll_publish_video:
                startActivity(new Intent(getActivity(), PublishVideoActivity.class));
                break;
            default:
                break;
        }
    }
}
